/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('pairec', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model CreateInstanceRequest {
  body?: any(name='body'),
}

model CreateInstanceResponseBody = {
  requestId?: string(name='requestId', description='Id of the request'),
  result?: {
    instanceId?: string(name='instanceId'),
  }(name='result'),
}

model CreateInstanceResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: CreateInstanceResponseBody(name='body'),
}

async function createInstance(request: CreateInstanceRequest): CreateInstanceResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return createInstanceWithOptions(request, headers, runtime);
}

async function createInstanceWithOptions(request: CreateInstanceRequest, headers: map[string]string, runtime: Util.RuntimeOptions): CreateInstanceResponse {
  Util.validateModel(request);
  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    body = request.body,
  };
  var params = new OpenApi.Params{
    action = 'CreateInstance',
    version = '2022-03-02',
    protocol = 'HTTPS',
    pathname = `/api/instances`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

model GetInstanceResponseBody = {
  requestId?: string(name='requestId', description='Id of the request'),
  result?: {
    chargeType?: string(name='chargeType', description='付费类型'),
    commodityCode?: string(name='commodityCode', description='商品code'),
    createTime?: string(name='createTime', description='创建时间'),
    description?: string(name='description', description='实例描述'),
    expiredTime?: string(name='expiredTime', description='到期时间'),
    inDebt?: boolean(name='inDebt', description='是否欠费'),
    instanceId?: string(name='instanceId', description='资源一级ID'),
    lockMode?: string(name='lockMode', description='锁定状态'),
    resourceGroupId?: string(name='resourceGroupId', description='资源组ID'),
    updateTime?: string(name='updateTime', description='更新时间'),
  }(name='result'),
}

model GetInstanceResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: GetInstanceResponseBody(name='body'),
}

async function getInstance(instanceId: string): GetInstanceResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return getInstanceWithOptions(instanceId, headers, runtime);
}

async function getInstanceWithOptions(instanceId: string, headers: map[string]string, runtime: Util.RuntimeOptions): GetInstanceResponse {
  instanceId = OpenApiUtil.getEncodeParam(instanceId);
  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
  };
  var params = new OpenApi.Params{
    action = 'GetInstance',
    version = '2022-03-02',
    protocol = 'HTTPS',
    pathname = `/api/instances/${instanceId}`,
    method = 'GET',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

model GetInstanceConfigResponseBody = {
  requestId?: string(name='requestId', description='Id of the request'),
  result?: map[string]any(name='result'),
}

model GetInstanceConfigResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: GetInstanceConfigResponseBody(name='body'),
}

async function getInstanceConfig(instanceId: string): GetInstanceConfigResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return getInstanceConfigWithOptions(instanceId, headers, runtime);
}

async function getInstanceConfigWithOptions(instanceId: string, headers: map[string]string, runtime: Util.RuntimeOptions): GetInstanceConfigResponse {
  instanceId = OpenApiUtil.getEncodeParam(instanceId);
  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
  };
  var params = new OpenApi.Params{
    action = 'GetInstanceConfig',
    version = '2022-03-02',
    protocol = 'HTTPS',
    pathname = `/api/instances/${instanceId}/config`,
    method = 'GET',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

model ListInstancesRequest {
  description?: string(name='description'),
  instanceId?: string(name='instanceId'),
  pageNumber?: int32(name='pageNumber'),
  pageSize?: int32(name='pageSize'),
}

model ListInstancesResponseBody = {
  requestId?: string(name='requestId', description='Id of the request'),
  result?: [ 
    {
      chargeType?: string(name='chargeType', description='付费类型'),
      commodityCode?: string(name='commodityCode', description='商品code'),
      createTime?: string(name='createTime', description='创建时间'),
      description?: string(name='description', description='实例描述'),
      expiredTime?: string(name='expiredTime', description='到期时间'),
      inDebt?: boolean(name='inDebt', description='是否欠费'),
      instanceId?: string(name='instanceId', description='资源一级ID'),
      lockMode?: string(name='lockMode', description='锁定状态'),
      resourceGroupId?: string(name='resourceGroupId', description='资源组ID'),
      status?: string(name='status', description='状态'),
      updateTime?: string(name='updateTime', description='更新时间'),
    }
  ](name='result'),
  totalCount?: int32(name='totalCount', description='总记录数。'),
}

model ListInstancesResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: ListInstancesResponseBody(name='body'),
}

async function listInstances(request: ListInstancesRequest): ListInstancesResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return listInstancesWithOptions(request, headers, runtime);
}

async function listInstancesWithOptions(request: ListInstancesRequest, headers: map[string]string, runtime: Util.RuntimeOptions): ListInstancesResponse {
  Util.validateModel(request);
  var query : map[string]any= {};
  if (!Util.isUnset(request.description)) {
    query['description'] = request.description;
  }
  if (!Util.isUnset(request.instanceId)) {
    query['instanceId'] = request.instanceId;
  }
  if (!Util.isUnset(request.pageNumber)) {
    query['pageNumber'] = request.pageNumber;
  }
  if (!Util.isUnset(request.pageSize)) {
    query['pageSize'] = request.pageSize;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'ListInstances',
    version = '2022-03-02',
    protocol = 'HTTPS',
    pathname = `/api/instances`,
    method = 'GET',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

model RenewInstanceRequest {
  duration?: int32(name='duration'),
  pricingCycle?: string(name='pricingCycle'),
  clientToken?: string(name='clientToken'),
  dryRun?: string(name='dryRun'),
}

model RenewInstanceResponseBody = {
  requestId?: string(name='requestId', description='Id of the request'),
  result?: boolean(name='result'),
}

model RenewInstanceResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: RenewInstanceResponseBody(name='body'),
}

async function renewInstance(instanceId: string, request: RenewInstanceRequest): RenewInstanceResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return renewInstanceWithOptions(instanceId, request, headers, runtime);
}

async function renewInstanceWithOptions(instanceId: string, request: RenewInstanceRequest, headers: map[string]string, runtime: Util.RuntimeOptions): RenewInstanceResponse {
  Util.validateModel(request);
  instanceId = OpenApiUtil.getEncodeParam(instanceId);
  var query : map[string]any= {};
  if (!Util.isUnset(request.clientToken)) {
    query['clientToken'] = request.clientToken;
  }
  if (!Util.isUnset(request.dryRun)) {
    query['dryRun'] = request.dryRun;
  }

  var body : map[string]any= {};
  if (!Util.isUnset(request.duration)) {
    body['duration'] = request.duration;
  }
  if (!Util.isUnset(request.pricingCycle)) {
    body['pricingCycle'] = request.pricingCycle;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'RenewInstance',
    version = '2022-03-02',
    protocol = 'HTTPS',
    pathname = `/api/instances/${instanceId}/actions/renew`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

model UpdateInstanceRequest {
  body?: any(name='body'),
}

model UpdateInstanceResponseBody = {
  requestId?: string(name='requestId', description='Id of the request'),
  result?: {
    chargeType?: string(name='chargeType', description='付费类型'),
    commodityCode?: string(name='commodityCode', description='商品code'),
    createTime?: string(name='createTime', description='创建时间'),
    description?: string(name='description', description='实例描述'),
    expiredTime?: string(name='expiredTime', description='到期时间'),
    inDebt?: boolean(name='inDebt', description='是否欠费'),
    instanceId?: string(name='instanceId', description='资源一级ID'),
    lockMode?: string(name='lockMode', description='锁定状态'),
    resourceGroupId?: string(name='resourceGroupId', description='资源组ID'),
    updateTime?: string(name='updateTime', description='更新时间'),
  }(name='result'),
}

model UpdateInstanceResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: UpdateInstanceResponseBody(name='body'),
}

async function updateInstance(instanceId: string, request: UpdateInstanceRequest): UpdateInstanceResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return updateInstanceWithOptions(instanceId, request, headers, runtime);
}

async function updateInstanceWithOptions(instanceId: string, request: UpdateInstanceRequest, headers: map[string]string, runtime: Util.RuntimeOptions): UpdateInstanceResponse {
  Util.validateModel(request);
  instanceId = OpenApiUtil.getEncodeParam(instanceId);
  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    body = request.body,
  };
  var params = new OpenApi.Params{
    action = 'UpdateInstance',
    version = '2022-03-02',
    protocol = 'HTTPS',
    pathname = `/api/instances/${instanceId}`,
    method = 'PUT',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

model UpdateInstanceConfigResponseBody = {
  requestId?: string(name='requestId', description='Id of the request'),
  result?: map[string]any(name='result'),
}

model UpdateInstanceConfigResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: UpdateInstanceConfigResponseBody(name='body'),
}

async function updateInstanceConfig(instanceId: string): UpdateInstanceConfigResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return updateInstanceConfigWithOptions(instanceId, headers, runtime);
}

async function updateInstanceConfigWithOptions(instanceId: string, headers: map[string]string, runtime: Util.RuntimeOptions): UpdateInstanceConfigResponse {
  instanceId = OpenApiUtil.getEncodeParam(instanceId);
  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
  };
  var params = new OpenApi.Params{
    action = 'UpdateInstanceConfig',
    version = '2022-03-02',
    protocol = 'HTTPS',
    pathname = `/api/instances/${instanceId}/config`,
    method = 'PUT',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

